# Maintainer : Felix Yan <felixonmars@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: William Rea <sillywilly@gmail.com>

pkgbase=python-chardet
pkgname=('python-chardet' 'python2-chardet')
pkgver=4.0.0
pkgrel=2
arch=('any')
url="https://github.com/chardet/chardet"
license=('LGPL')
makedepends=('python-setuptools' 'python2-setuptools')
checkdepends=('python-pytest' 'python2-pytest')
source=("https://pypi.io/packages/source/c/chardet/chardet-${pkgver}.tar.gz")
sha512sums=('ebd7f420e1094445270db993f6373ffe7370419e002b0bb13299dc6c9b0f7c4e77b0f44f871fba6371e6869e7c86728514367db377e3137487a3acf50cb81e96')

prepare() {
   cp -a chardet-$pkgver{,-py2}
}

build() {
   cd "$srcdir"/chardet-$pkgver
   python setup.py build

   cd "$srcdir"/chardet-$pkgver-py2
   python2 setup.py build
}

check() {
   cd "$srcdir"/chardet-$pkgver
   python -m pytest

   cd "$srcdir"/chardet-$pkgver-py2
   python2 -m pytest
}

package_python-chardet() {
   depends=('python')
   pkgdesc="Python3 module for character encoding auto-detection"

   cd chardet-$pkgver
   python setup.py install --root="$pkgdir" --optimize=1
}

package_python2-chardet() {
   depends=('python2-setuptools')
   pkgdesc="Python2 module for character encoding auto-detection"

   cd chardet-$pkgver-py2
   python2 setup.py install --root="$pkgdir" --optimize=1

   # To avoid file conflict with the python3 version
   mv "$pkgdir"/usr/bin/chardetect{,-py2}
}
